package com.amkai.aes.webservice.binary.objecthandler.conflict;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.amkai.aes.aescommon.AESSettings;
import com.amkai.aes.aescommon.service.conflict.ConflictCheckingJob;
import com.amkai.aes.aescommon.service.conflict.ConflictCheckingResult;
import com.amkai.aes.server.conflict.ConflictCheckingProvider;
import com.amkai.aes.webservice.binary.JobObjectHandler;

public class ConflictCheckingHandler implements JobObjectHandler<ConflictCheckingJob, Serializable, ConflictCheckingResult> {
	private static final Log logger = LogFactory.getLog(ConflictCheckingHandler.class);
			
	@Override
	public ConflictCheckingResult process(ConflictCheckingJob job, Serializable object) throws Exception {
		// KKORNEL: AES-16008
		if (AESSettings.CONFLICT_CHECKING_ENABLED) {
			ConflictCheckingProvider em = new ConflictCheckingProvider();
			try {
				return em.processJob(job, object);
			} catch (Throwable e) {
				logger.error("ConflictCheckingHandler: ", e);
				throw new Exception(e);
			}
		} else {
			return new ConflictCheckingResult();
		}
	}

}
